<template>
  <view :style="themeColor">
    <view class="page">
      <!---flex布局flex布局开始-->
      <view class="flex flex-direction flex-wrap align-stretch benben-flex-layout register_flex_0">
        <view class='flex flex-wrap align-center justify-center register_fd0_0'>
          <image class='register_fd0_0_c0' mode="aspectFit" :src='STATIC_URL+"222.png"'></image>
        </view>
        <view class='flex flex-wrap align-center register_fd0_1'>
          <image class='register_fd0_1_c0' mode="aspectFit" :src='STATIC_URL+"230.png"'></image>
          <benben-input class='flex-sub register_fd0_1_c1' type="number" :placeholder="$t('请输入手机号')" confirm-type="done"
            :maxlength="11" placeholder-style="color:#999;font-size:32rpx" v-model="mobile" />
        </view>
        <view class='flex flex-wrap align-center register_fd0_2'>
          <image class='register_fd0_1_c0' mode="aspectFit" :src='STATIC_URL+"232.png"'></image>
          <benben-input class='flex-sub register_fd0_1_c1' type="number" :placeholder="$t('请输入验证码')" confirm-type="done"
            :maxlength="6" placeholder-style="color:#999;font-size:32rpx" v-model="code" />
          <benben-send-verification-code key='1707098346614' ref="vCode1707098346614" class=' register_fd0_2_c2'
            :after-text="$t('后重新获取')" :before-text="$t('获取验证码')" :emptye-text="$t('请输入手机号')"
            :validate-text="$t('请输入正确的手机号')" account-type='phone' :auto='true' type='1'
            :phone="mobile"></benben-send-verification-code>
        </view>
        <view class='flex flex-wrap align-center register_fd0_2'>
          <image class='register_fd0_1_c0' mode="aspectFit" :src='STATIC_URL+"231.png"'></image>
          <benben-flex-password-diy v-model="password" class-name="flex flex align-center register_fd0_3_c1"
            :placeholder="$t('请输入密码(6~12位字母+数字)')" :maxlength="12" :default-type='true'
            placeholder-style="color:#999;font-size:32rpx">
            <template #show>
              <text class='fu-iconfont2  register_fd0_3_c1_icon1' data-type="show">&#xE837;</text>
            </template>
            <template #hide>
              <text class='fu-iconfont2  register_fd0_3_c1_icon1' data-type="hide">&#xEBCC;</text>
            </template>
          </benben-flex-password-diy>
        </view>
        <!-- <view class='flex flex-wrap align-center register_fd0_2'>
          <image class='register_fd0_1_c0' mode="aspectFit" :src='STATIC_URL+"233.png"'></image>
          <benben-input class='flex-sub register_fd0_1_c1' type="text" :placeholder="$t('请输入邀请码（选填）')"
            confirm-type="done" :maxlength="-1" placeholder-style="color:#999;font-size:32rpx" v-model="invite_code" />
        </view> -->
        <button class='register_fd0_5' @tap.stop="registerFunc()">{{$t('注册')}}</button>
        <view class='flex flex-wrap align-center justify-center'>
          <text class='register_fd0_6_c0'>{{$t('已有账号，前去')}}</text>
          <text class='register_fd0_6_c1' @tap.stop="handleJumpDiy" data-type="redirectTo"
            :data-url="`/pages/tabBar/login/login`">{{$t('登录')}}</text>
        </view>
        <view class='flex flex-wrap align-center justify-center register_fd0_7'>
          <benben-flex-switch-new class-name='flex flex' v-model="is_tk" :disabled='false'>
            <template v-slot:checked>

              <view class='flex flex position-relative align-center'>
                <image class='register_checkfd0_7_c0_c0_c0' mode="aspectFit" :src='STATIC_URL+"3.png"'></image>
              </view>

            </template>
            <template v-slot:unchecked>

              <view class='flex flex position-relative justify-end align-center'>
                <image class='register_noCheckfd0_7_c0_c1_c0' mode="aspectFit" :src='STATIC_URL+"213.png"'></image>
              </view>

            </template>
          </benben-flex-switch-new>
          <text class='register_fd0_7_c1'>{{$t('已阅读并同意')}}</text>
          <text class='register_fd0_7_c2' @tap.stop="handleJumpDiy" data-type="navigateTo"
            :data-url="`/pages/dlzc/agreements/agreements`">{{$t('《用户注册协议》')}}</text>
          <text class='register_fd0_7_c3'>{{$t('与')}}</text>
          <text class='register_fd0_7_c2' @tap.stop="handleJumpDiy" data-type="navigateTo"
            :data-url="`/pages/dlzc/privacyPolicy/privacyPolicy`">{{$t('《隐私政策》')}}</text>
        </view>
      </view>

      <!---flex布局flex布局结束-->
      <view class="flex flex-wrap align-center justify-between benben-position-layout flex register_flex_1"
        :style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
        <view class='flex flex-wrap align-center register_fd1_0' @tap.stop="handleJumpDiy" data-type="back"
          data-url="1">
        </view>
        <view class='flex flex-wrap align-center register_fd1_0'>
        </view>

      </view>
      <view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>


    </view>
  </view>
</template>
<script>
  import {
    validate
  } from '@/common/utils/validate.js';
  import md5 from 'js-md5';
  export default {
    components: {},


    data() {
      return {
        "is_tk": false,
        "mobile": "",
        "code": "",
        "password": "",
        "dataList": {
          "userinfo": {
            "user_token": "",
            "id": "",
            "avatar": "",
            "real_name": "",
            "nickname": "",
            "email": "",
            "gender": "",
            "mobile": "",
            "birthday": ""
          }
        },
        "invite_code": ""
      };
    },
    computed: {
      themeColor() {
        return this.$store.getters.themeColor
      },
      /**
       * @returns
       * Android       安卓
       * IOS       苹果
       * Web       H5 或 pc
       * Wechat       微信小程序
       * Alipay       支付宝小程序
       * Baidu       百度小程序
       * ByteBounce       抖音小程序
       * 360       360小程序
       * FastApp       快应用
       */
      appSystemIdentification() {
        return this.$store.state.appSystemIdentification
      }
    },
    watch: {},
    onLoad(options) {

    },
    onUnload() {

    },
    onReady() {

    },
    onShow() {

    },
    onHide() {

    },
    onResize() {

    },
    onPullDownRefresh() {

    },
    onReachBottom(e) {

    },
    onPageScroll(e) {

    },
    methods: {
      //注册
      async registerFunc() {
        if (!validate(this.mobile, 'require')) {
          this.$message.info(global.i18n.t('请输入手机号'));
          return false;
        }
        if (!validate(this.mobile, 'phone')) {
          this.$message.info(global.i18n.t('请输入正确的手机号'));
          return false;
        }
        if (!validate(this.code, 'require')) {
          this.$message.info(global.i18n.t('请输入验证码'));
          return false;
        }
        if (!validate(this.code, 'captcha')) {
          this.$message.info(global.i18n.t('请输入正确的验证码'));
          return false;
        }
        if (!validate(this.password, 'require')) {
          this.$message.info(global.i18n.t('请输入密码'));
          return false;
        }
        if (!validate(this.password, 'password')) {
          this.$message.info(global.i18n.t('请输入正确的密码（6~12位字母+数字）'));
          return false;
        }
        if (this.is_tk === false) {
          this.$message.info(global.i18n.t('请勾选协议'));
          return false;
        }
        //请求方法
        //数据验证

        let datadataList = await this.$api.dbPost(global.apiUrls.registerUser, {
          telPhone: this.mobile,
          vCode: this.code,
          password: md5(this.password),
          invite_code: this.invite_code,
          // user_source: this.appSystemIdentification
        });
        if (!datadataList) return
        if (datadataList.data.code != 0) {
          this.$message.info(datadataList.data.msg);
          return
        }
        let infodataList = datadataList.data;
        this.dataList = infodataList.data
        console.log('dataList', infodataList.data)
        this.$store.commit('saveToken', this.dataList.token)
        this.$store.commit('updateUserInfo', this.dataList)
        this.$urouter.switchTab(`/pages/tabBar/home/home`);
      },
    }
  };
</script>
<style lang="scss" scoped>
  .page {
    width: 100vw;
    overflow-x: hidden;
    min-height: calc(100vh - var(--window-bottom));
    background: var(--benbenbgColor1);
    background-size: 100% auto;
  }

  .register_flex_0 {
    padding: 0rpx 56rpx 0rpx 56rpx;
  }

  .register_fd0_7_c3 {
    color: var(--benbenFontColor2);
    font-size: 28rpx;
    font-weight: 400;
    line-height: 33rpx;
  }

  .register_fd0_7_c2 {
    color: rgba(0, 137, 255, 1);
    font-size: 28rpx;
    font-weight: 400;
    line-height: 33rpx;
  }

  .register_fd0_7_c1 {
    color: var(--benbenFontColor2);
    font-size: 28rpx;
    font-weight: 400;
    line-height: 33rpx;
    margin: 0rpx 0rpx 0rpx 16rpx;
  }

  .register_noCheckfd0_7_c0_c1_c0 {
    border-radius: 24rpx 24rpx 24rpx 24rpx;
    width: 30rpx;
    height: 30rpx;
  }

  .register_checkfd0_7_c0_c0_c0 {
    width: 30rpx;
    height: 30rpx;
    border-radius: 24rpx 24rpx 24rpx 24rpx;
  }

  .register_fd0_7 {
    width: 750rpx;
    position: fixed;
    bottom: calc(48rpx + var(--window-bottom));
    left: 0rpx;
  }

  .register_fd0_6_c1 {
    color: rgba(0, 137, 255, 1);
    font-size: 28rpx;
    font-weight: 400;
    line-height: 40rpx;
  }

  .register_fd0_6_c0 {
    color: var(--benbenFontColor2);
    font-size: 28rpx;
    font-weight: 400;
    line-height: 40rpx;
  }

  .register_fd0_5 {
    background: var(--benbenbgColor7);
    border-radius: 50rpx 50rpx 50rpx 50rpx;
    font-size: 32rpx;
    color: var(--benbenFontColor3);
    width: 638rpx;
    height: 88rpx;
    line-height: 88rpx;
    margin: 104rpx 0rpx 32rpx 0rpx;
  }

  .register_fd0_3_c1_icon1 {
    width: 88rpx;
    line-height: 88rpx;
    text-align: center;
    font-size: 40rpx;
  }

  ::v-deep .register_fd0_3_c1 {
    height: 45rpx;
    width: 560rpx;
    font-size: 32rpx;
    margin: 0rpx 0rpx 0rpx 32rpx;
  }

  .register_fd0_2_c2 {
    min-width: 250rpx;
    line-height: 42rpx;
    text-align: center;
    font-size: 28rpx;
    color: rgba(0, 167, 255, 1);
    border-radius: 21rpx 21rpx 21rpx 21rpx;
  }

  .register_fd0_2 {
    border-bottom: 1px solid #eee;
    padding: 40rpx 0rpx 40rpx 0rpx;
  }

  .register_fd0_1_c1 {
    height: 45rpx;
    margin: 0rpx 0rpx 0rpx 32rpx;
    color: var(--benbenFontColor0);
    font-size: 32rpx;
    font-weight: 400;
    line-height: 45rpx;
  }

  .register_fd0_1_c0 {
    width: 34rpx;
    height: 34rpx;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
  }

  .register_fd0_1 {
    border-bottom: 1px solid #eee;
    padding: 40rpx 0rpx 40rpx 0rpx;
    margin: 40rpx 0rpx 0rpx 0rpx;
  }

  .register_fd0_0_c0 {
    width: 180rpx;
    height: 180rpx;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
  }

  .register_fd0_0 {
    margin: 140rpx 0rpx 0rpx 0rpx;
  }

  .register_flex_1 {
    width: 750rpx;
    height: 88rpx;
    overflow: hidden;
    z-index: 10;
    top: 0rpx;
  }

  .register_fd1_0 {
    width: 100rpx;
    height: 88rpx;
  }
</style>
